package com.landian.springdata.demo.impl.service;

import com.landian.springdata.demo.api.service.OrderDetailService;
import com.landian.springdata.demo.api.vo.OrderDetail;
import com.landian.springdata.demo.impl.converter.OrderDetailConverter;
import com.landian.springdata.demo.impl.entity.OrderDetailEntity;
import com.landian.springdata.demo.impl.entity.QOrderDetailEntity;
import com.landian.springdata.demo.impl.predicable.OrderDetailPredicable;
import com.landian.springdata.demo.impl.repository.OrderDetailRepository;
import com.querydsl.core.types.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderDetailServiceImpl implements OrderDetailService {

    @Autowired
    private OrderDetailRepository orderDetailRepository;

    private Path getIdPath(){
        return OrderDetailPredicable.idPath;
    }

    private QOrderDetailEntity getQEntity(){
        return OrderDetailPredicable.QEntity;
    }

    @Override
    public List<OrderDetail> findByOrderId(String orderId) {
        List<OrderDetailEntity> list = orderDetailRepository.findByPathEqual(getQEntity().orderId, orderId);
        return OrderDetailConverter.vo.convert(list);
    }
}
